const app = new(require('koa'))()
const router = new(require('koa-router'))()
const cors = require('@koa/cors')
const Mock = require('mockjs')
const {
    exec
} = require('./mysql')

app.use(cors())


router.get("/api/search", async (ctx) => {
    const { keyword } = ctx.query
    console.log(keyword);
    let data = await exec(`select * from houseList where title like '%${keyword}%'`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/HomeList", async (ctx) => {
    let data = await exec(`select * from houseList`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/broker", async (ctx) => {
    let data = await exec(`select * from broker`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/building", async (ctx) => {
    let data = await exec(`select * from building`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/search1", async (ctx) => {
    const { keyword } = ctx.query
    let data = await exec(`select * from building where title like '%${keyword}%'`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/search2", async (ctx) => {
    let data = await exec(`select * from building where title like '%${keyword}%'`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/rent", async (ctx) => {
    let data = await exec(`select * from rent`)
    ctx.body = {
        code: 200,
        data
    }
})


router.get("/api/information", async (ctx) => {
    let data = await exec(`select * from information`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/market", async (ctx) => {
    let data = await exec(`select * from market`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/brokerData", async (ctx) => {
    let data = await exec(`select * from brokerData`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/Groupbuy", async (ctx) => {
    let data = await exec(`select * from groupbuy`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/LiveBroadcast", async (ctx) => {
    let data = await exec(`select * from livebroadcast`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/search3", async (ctx) => {
    let data = await exec(`select * from houseprice where price like '%${keyword}%'`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/HousePrice", async (ctx) => {
    let data = await exec(`select * from houseprice`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/search4", async (ctx) => {
    let data = await exec(`select * from housetype1 where name like '%${keyword}%'`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/HouseType1", async (ctx) => {
    let data = await exec(`select * from housetype1`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/search4", async (ctx) => {
    let data = await exec(`select * from housetype2 where name1 like '%${keyword}%'`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/HouseType2", async (ctx) => {
    let data = await exec(`select * from housetype2`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/ReleaseList", async (ctx) => {
    let data = await exec(`select * from releaselist`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/CollectList", async (ctx) => {
    let data = await exec(`select * from collectlist`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/History", async (ctx) => {
    let data = await exec(`select * from history`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/PayDetail", async (ctx) => {
    let data = await exec(`select * from paydetail`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/AreaList", async (ctx) => {
    let data = await exec(`select * from arealist`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/AddressList", async (ctx) => {
    let data = await exec(`select * from alladdress`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/Station", async (ctx) => {
    let data = await exec(`select * from station`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/Message", async (ctx) => {
    let data = await exec(`select * from message`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/Types", async (ctx) => {
    let data = await exec(`select * from types`)
    ctx.body = {
        code: 200,
        data
    }
})

router.get("/api/AreaChoose", async (ctx) => {
    let data = await exec(`select * from areachoose`)
    ctx.body = {
        code: 200,
        data
    }
})

app.use(router.routes())

app.listen(3000)